using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace PeDALS.Utilities.Hasher
{
    public static class GenerateHash
    {
        public static string GetMD5(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path);
            MD5 md5 = new MD5CryptoServiceProvider();
            string strHex = "";

            HashValue = md5.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }

        public static string GetSHA1(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path); 
            SHA1Managed SHhash = new SHA1Managed();
            string strHex = "";

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }

        public static string GetSHA256(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path); 
            SHA256Managed SHhash = new SHA256Managed();
            string strHex = "";

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }

        public static string GetSHA384(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path); 
            SHA384Managed SHhash = new SHA384Managed();
            string strHex = "";

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }

        public static string GetSHA512(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path); 
            SHA512Managed SHhash = new SHA512Managed();
            string strHex = "";

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }
    }
}
